package com.alstudio.utils.android.keyboard;

import android.app.Activity;
import android.content.Context;
import android.view.inputmethod.InputMethodManager;

import com.alstudio.ui.base.BaseActivity;

/**
 * 键盘管理器，提供显示、隐藏键盘方法
 * 
 * @author alonso lee
 * 
 */
public class ALKeyBoardManager {

	/**
	 * 显示键盘
	 * 
	 * @param context
	 */
	public static void showKeyBoard(BaseActivity context) {
		try {
			InputMethodManager imm = (InputMethodManager) context
					.getSystemService(Context.INPUT_METHOD_SERVICE);
			imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * 隐藏键盘
	 * 
	 * @param context
	 */
	public static void dismissKeyBoard(BaseActivity context) {
		// Hide the keyboard
		try {
			InputMethodManager inputManager = (InputMethodManager) context
					.getSystemService(Context.INPUT_METHOD_SERVICE);
			if (((Activity) context).getCurrentFocus() != null) {
				inputManager.hideSoftInputFromWindow(((Activity) context)
						.getCurrentFocus().getWindowToken(),
						InputMethodManager.HIDE_NOT_ALWAYS);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public interface ALKeyBoardStateListener {
		public void onKeyBoardShow();

		public void onKeyBoardDismiss();
	}

}
